# -*- coding: utf-8 -*-

from django.shortcuts import render_to_response
from Evidencija2.GUI.models.Meeting import Meeting
from datetime import date, time
import json
from django.http import HttpResponse

meetings2011 = {'2011-050':Meeting(code = '2011-050', date = date(2011, 1, 30), time=time(9, 30), type = 'Prvo bogosluzje'),
                '2011-051':Meeting(code = '2011-051', date = date(2011, 1, 30), time=time(11, 30), type = 'Drugo bogosluzje'),
                '2011-052':Meeting(code = '2011-052', date = date(2011, 1, 30), time=time(11, 30), type = 'Biblijsko proucavanje')};

meetings2012 = {'2012-130':Meeting(code = '2012-130', date = date(2012, 1, 30), time=time(9, 30), type = 'Prvo bogosluzje'),
                '2012-131':Meeting(code = '2012-131', date = date(2012, 1, 30), time=time(11, 30), type = 'Drugo bogosluzje'),
                '2012-132':Meeting(code = '2012-132', date = date(2012, 1, 30), time=time(11, 30), type = 'Biblijsko proucavanje')};

meetings2013 = {'2013-150':Meeting(code = '2013-150', date = date(2013, 1, 30), time=time(9, 30), type = 'Prvo bogosluzje'),
                '2013-151':Meeting(code = '2013-151', date = date(2013, 1, 30), time=time(11, 30), type = 'Drugo bogosluzje'),
                '2013-152':Meeting(code = '2013-152', date = date(2013, 1, 30), time=time(19, 00), type = 'Bibbblijsko proucavanje')};

def list(request):
    years = [2013, 2012, 2011];
   
    #meetings = getMeetings(years[len(years)-1:])

    return render_to_response('meetings.html', {'years': years})

def new(request):
    return render_to_response('meetingEdit.html')

def edit(request, id):
    return render_to_response('meetingEdit.html')

def getMeetings(year):
    if year:
        return Meeting.objects.filter(pub_date__year=year)

    return []

def getYearMeetings(request):

    result = []
    year = request.GET['year']

    if year == '2011':
        result = meetings2011
    elif year == '2012':
        result = meetings2012
    elif year == '2013':
        result = meetings2013


    return HttpResponse(json.dumps(result), content_type='application/json')
